<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <input type="file" accept="" onchange="submitFile(event)" value="文件" />
    <input type="file" accept="" onchange="submitFile2(event)" value="图片" />
    <script>
      /*
        readAsDataURL 返回的是一个url url直接可以网页浏览
        readAsText 返回一个流
        */
      submitFile = function (event) {
        var reader = new FileReader();
        reader.readAsText(event.target.files[0], 'UTF-8'); //读取文件
        reader.onload = function (evt) {
          console.log(evt.target);
          const img = new Image();
          img.src = reader.result;
          document.body.appendChild(img); // reader.result为获取结果
        };
      };

      submitFile2 = function (event) {
        var reader = new FileReader();
        reader.readAsDataURL(event.target.files[0]);
        reader.onload = function (evt) {
          console.log(evt);
          const img = new Image();
          img.src = reader.result;
          document.body.appendChild(img); // reader.result为获取结果
        };
      };
    </script>
  </body>
</html>
